package com.cwvs.cat.adapter;

import java.util.List;

import net.tsz.afinal.FinalBitmap;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.cwvs.cat.R;
import com.cwvs.cat.bean.MyClubs;
import com.cwvs.cat.net.Port;

public class ClubListAdapter extends BaseAdapter {

	private List<MyClubs> list_contact;
	private LayoutInflater inflater;
	private FinalBitmap fb;
	public ClubListAdapter() {
		// TODO Auto-generated constructor stub
	}

	public ClubListAdapter(Activity ac, List<MyClubs> list) {
		// TODO Auto-generated constructor stub
		this.inflater = LayoutInflater.from(ac);
		this.list_contact = list;
		fb = FinalBitmap.create(ac);
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list_contact.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return list_contact.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder viewholder;
		if (convertView == null) {
			convertView = inflater.inflate(R.layout.item_list_club, null);
			viewholder = new ViewHolder();
			viewholder.txt_club_name = (TextView) convertView.findViewById(R.id.txt_club_name);
			viewholder.introduce = (TextView) convertView.findViewById(R.id.introduce);
			viewholder.num = (TextView) convertView.findViewById(R.id.num);
			viewholder.moreClub = (ImageView) convertView.findViewById(R.id.moreClub);
			convertView.setTag(viewholder);

		} else {
			viewholder = (ViewHolder) convertView.getTag();
		}
		viewholder.txt_club_name.setText(list_contact.get(position).name);
		viewholder.introduce.setText(list_contact.get(position).introduce);
		viewholder.num.setText(list_contact.get(position).count);
		if (!list_contact.get(position).background_pic.equals("null")&&!list_contact.get(position).background_pic.equals("")) {
			if (list_contact.get(position).background_pic.contains("http")) {
				fb.display(viewholder.moreClub,list_contact.get(position).recent_news_pic);
			}else {
				fb.display(viewholder.moreClub,Port.getImg+list_contact.get(position).recent_news_pic);
			}
		}
		return convertView;
	}

	class ViewHolder {
		TextView txt_club_name, txt_club_time, num,introduce;
		ImageView moreClub;
	}

}
